<script setup lang="ts">
import { onBeforeMount, ref } from "vue";
import { useCounterStore } from "../stores/counterStore";
import eventBus from '../utils/eventBus';

import Father from "./Father.vue";

const counterStore = useCounterStore();
const countObject = ref(counterStore);

const add = () => {
  counterStore.add();
};

const sub = () => {
  counterStore.sub();
};

let removeMakeMoneyListener = eventBus.on("makeMoney", () => {
  counterStore.add();
});

let removeSpendMoneyListener = eventBus.on("spendMoney", () => {
  counterStore.sub();
});


</script>

<template>
  <div class="grandpa">
    爷爷：(家庭总资产为：{{ countObject.count }})
    <button @click="add">赚钱</button>
    <button @click="sub">花钱</button>
    <Father></Father>
  </div>
</template>

<style scoped>
.grandpa {
  background-color: #000000;
  color: #ffffff;
  width: 1000px;
  height: 600px;
}
</style>